home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / PASCSRC.ZIP / AMORT4.PAS < prev    next >
Pascal/Delphi Source File  |  1988-01-15  |  3KB  |  98 lines

  1. program Amortization_Table;
  2.  
  3. var Month : 1..12;
  4.     Starting_Month : 1..12;
  5.     Balance : real;
  6.     Payment : real;
  7.     Interest_Rate : real;
  8.     Annual_Accum_Interest : real;
  9.     Year : integer;
  10.     Number_Of_Years : integer;
  11.     Original_Loan : real;
  12.  
  13.  
  14. procedure Calculate_Payment; (* **************** calculate payment *)
  15. var Temp : real;
  16.     Index : integer;
  17. begin
  18.    Temp := 1.0;
  19.    for Index := 1 TO 12*Number_Of_Years do
  20.      Temp := Temp * (1.0 + Interest_Rate);
  21.    Payment := Original_Loan*Interest_Rate/(1.0 - 1.0/Temp);
  22. end;
  23.  
  24. procedure Initialize_Data; (* ******************** initialize data *)
  25. begin
  26.    Writeln('   Pascal amortization program');
  27.    Writeln;
  28.    Write('Enter amount borrowed                         ');
  29.    Readln(Original_Loan);
  30.    Balance := Original_Loan;
  31.    Write('Enter interest rate as percentage (i.e. 13.5) ');
  32.    Readln(Interest_Rate);
  33.    Interest_Rate := Interest_Rate/1200.0;
  34.    Write('Enter number of years of payoff               ');
  35.    Readln(Number_Of_Years);
  36.    Write('Enter month of first payment (i.e. 5 for May) ');
  37.    Readln(Starting_Month);
  38.    Write('Enter year of first payment (i.e. 1985)       ');
  39.    Readln(Year);
  40.    Calculate_Payment;
  41.    Annual_Accum_Interest := 0.0; (* This is to accumulate Interest *)
  42. end;
  43.  
  44. procedure Print_Annual_Header; (* ************ print annual header *)
  45. begin
  46.    Writeln;
  47.    Writeln;
  48.    Writeln('Original loan amount = ',Original_Loan:10:2,
  49.            '   Interest rate = ',1200.0*Interest_Rate:6:2,'%');
  50.    Writeln;
  51.    Writeln('Month    payment  interest    princ   balance');
  52.    Writeln;
  53. end;
  54.  
  55. procedure Calculate_And_Print; (* ************ calculate and print *)
  56. var Interest_Payment : real;
  57.     Principal_Payment : real;
  58. begin
  59.    if Balance > 0.0 then begin
  60.       Interest_Payment := Interest_Rate * Balance;
  61.       Principal_Payment := Payment - Interest_Payment;
  62.       if Principal_Payment > Balance then begin  (* loan payed off *)
  63.          Principal_Payment := Balance;              (* this month *)
  64.          Payment := Principal_Payment + Interest_Payment;
  65.          Balance := 0.0;
  66.       end
  67.       else begin  (* regular monthly payment *)
  68.          Balance := Balance - Principal_Payment;
  69.       end;
  70.       Annual_Accum_Interest := Annual_Accum_Interest
  71.                                                + Interest_Payment;
  72.       Writeln(Month:5,Payment:10:2,Interest_Payment:10:2,
  73.               Principal_Payment:10:2,Balance:10:2);
  74.    end; (* of if Balance > 0.0 then *)
  75. end;
  76.  
  77. procedure Print_Annual_Summary; (* ********** print annual summary *)
  78. begin
  79.    Writeln;
  80.    Writeln('Total interest for ',Year:5,' = ',
  81.             Annual_Accum_Interest:10:2);
  82.    Annual_Accum_Interest := 0.0;
  83.    Year := Year + 1;
  84.    Writeln;
  85. end;
  86.  
  87. begin   (* ******************************************* main program *)
  88.    Initialize_Data;
  89.    repeat
  90.       Print_Annual_Header;
  91.       for Month := Starting_Month to 12 do begin
  92.          Calculate_And_Print;
  93.       end;
  94.       Print_Annual_Summary;
  95.       Starting_Month := 1;
  96.    until Balance <= 0.0;
  97. end. (* of main program *)
  98.